#!/bin/bash

if [ "$(csrutil authenticated-root status | grep status | awk -F: '{print $NF}' | awk '{print $1}')" = "enabled" ] || [ "$(csrutil status | grep status | awk -F: '{print $NF}' | awk '{print $1}')" = "enabled" ];then
    csrutil disable
    csrutil authenticated-root disable    
    echo "已解锁csr, authenticated-root，请重启后再次进入Recovery运行本脚本进行删除快照操作"
else
    diskutil list
    echo "请输入BigSur系统盘(非数据)分区名称(例如BigSur)，按回车确认:"
    read name
    echo "请输入BigSur系统盘(非数据)的标识符(例如disk4s5)，按回车确认:"
    read identifier
    mount -uw "/Volumes/$name"
    /System/Library/Filesystems/apfs.fs/Contents/Resources/apfs_systemsnapshot -r "" -v "/Volumes/$name"
    arr=($(diskutil apfs listSnapshots $identifier | grep Name | awk '{print $NF}'))
    for element in ${arr[@]}
    do
        diskutil apfs deletesnapshot $identifier -name $element
    done
    echo "删除快照完成,重启以后将以真实系统启动，感谢使用及叔删除快照脚本，QQ群：1043960768"
fi

